﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace parkingclient
{
    public partial class user_login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblError.Text = "";

            if (Session["user"] == null)
            {
                lblWelcome.Text = "[<a href='user_login.aspx'>Login</a>]   [<a href='registration.aspx'>Register</a>]";
            }
            else if (int.Parse(Session["userType"].ToString()) == 3) //for admin, add link to the admin dashboard
            {
                lblWelcome.Text = "Welcome " + Session["user"] + "   [<a href='admin_dashboard.aspx'>Admin Dashboard</a>]    [<a href='user_logout.aspx'>Logout</a>]";
            }
            else
            {
                lblWelcome.Text = "Welcome " + Session["user"] + "   [<a href='user_logout.aspx'>Logout</a>]";
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            
            ParkingService.WebService1 parking = new ParkingService.WebService1();
            bool loginres = parking.login(txtUsername.Text, txtPassword.Text);

            if (loginres == false)
            {
                lblError.Text = "Login failed. Please try again";
            }
            else
            {
                Session["user"] = txtUsername.Text;
                Session["userType"] = parking.getAccountTypeByEmail(txtUsername.Text);
                Response.Redirect("reservation.aspx");
            }

        }

        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            Response.Redirect("registration.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("reservation.aspx");
        }
    }
}